import {
	request
} from '@/utils/request'

/**
 * 用户信息获取
 
 */
export const getUsInfo = () => {
	return request({
		url: '/userinfo/getUsInfo',
		method: 'GET',
	})
}
/**
 * 更新用户信息
 
 */
export const updateUserInfo = (data) => {
	return request({
		url: '/userinfo/updateUserInfo',
		method: 'POST',
		data: data
	})
}
/**
 * 地址三级联动
 
 */
export const getAddressSelect = (level, parent_code) => {
	return request({
		url: '/userinfo/getAddressSelect',
		method: 'GET',
		params: { // GET参数应该放在params中
			level,
			parent_code
		}
	})
}
/**
 * 惠企政策
 
 */
export const myPolicy = (params) => {
	return request({
		url: '/userinfo/myPolicy',
		method: 'GET',
		params: params
	})
}
/**
 * 我的供需
 
 */
export const mySupplyDemand = (params) => {
	return request({
		url: '/userinfo/mySupplyDemand',
		method: 'GET',
		params: params
	})
}
/**
 * 意向空间
 
 */
export const mySpace = (params) => {
	return request({
		url: '/userinfo/mySpace',
		method: 'GET',
		params: params
	})
}
/**
 * 人才需求
 
 */
export const myRecruitment = (params) => {
	return request({
		url: '/userinfo/myRecruitment',
		method: 'GET',
		params: params
	})
}
/**
 * 我的金融
 
 */
export const myFinance = (params) => {
	return request({
		url: '/userinfo/myFinance',
		method: 'GET',
		params: params
	})
}
/**
 * 我的活动
 
 */
export const myActivity = (params) => {
	return request({
		url: '/userinfo/myActivity',
		method: 'GET',
		params: params
	})
}
/**
 * 我的反馈
 
 */
export const myFeedback = (params) => {
	return request({
		url: '/userinfo/myFeedback',
		method: 'GET',
		params: params
	})
}
/**
 * 我的反馈详情
 
 */
export const myFeedbackDetali = (params) => {
	return request({
		url: '/userinfo/myFeedbackDetali',
		method: 'GET',
		params: params
	})
}
/**
 * 留言箱
 
 */

export const mySaveFeedback = (data) => {
	return request({
		url: '/userinfo/mySaveFeedback',
		method: 'POST',
		data: data,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}
/**
 * 上传附件
 * @param {File} file - 要上传的文件对象
 */
export const uploadImage = (file) => {
	return new Promise((resolve, reject) => {
		const token = uni.getStorageSync('token')
		uni.uploadFile({
			url: 'https://gxq.jifgou.com/api/userinfo/uploadImage',
			filePath: file.path, // 直接使用文件路径
			name: 'image', // 后端接收的字段名
			header: {
				'Authorization': `Bearer ${token}`,
			},
			success: (res) => {
				try {
					const data = JSON.parse(res.data)
					resolve(data)
				} catch (e) {
					reject(new Error('解析响应失败'))
				}
			},
			fail: (err) => {
				reject(err)
			},
		})
	})
}
/**
 * 我的预约
 
 */
export const myReservation = (params) => {
	return request({
		url: '/userinfo/myReservation',
		method: 'GET',
		params: params
	})
}
/**
 * 获取用户协议|隐私协议
 
 */
export const agreement = (params) => {
	return request({
		url: '/index/agreement',
		method: 'GET',
		params: params
	})
}